cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA2.log", replace

clear all
set more off

matrix Results = J(48, 10, 0)

use "RawData/GallupDataBJPS.dta", clear
// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Approval")
// Drops Obs. w/o Party ID
drop if pres_approve == -9 | pres_approve == -99

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
gen quarter = qofd(middle_date)
format quarter %tq

levelsof quarter, local (fourths) 

local year = 1953
foreach i of local fourths {
local counter = `i' + 28
tab series if quarter == `i'
local row = 1 + mod(`counter', 4)*2 + floor((`year' - 1953) / 10)*8
local column = 1 + mod((`year' - 1953), 10)
matrix Results[`row', `column'] = r(N)
matrix Results[`row'+1, `column'] = -r(r)
local year = `year' + floor(`counter' / 4)
}

matlist Results

log close
